<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/28-9:24
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */
namespace App\Http\Controllers\Web\Member\Buyer;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;

class OrderExpressBuyerController extends BaseController
{
    protected $api_url = [
        'show' => ['get', 'buyer/orders/%d/order_express/%d'],
        'store' => ['post', 'seller/orders/%d/order_express'],
    ];

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function show($order_id, $order_express_id = 0)
    {
        $ret = http_web($this->api_url['show'], [$order_id, $order_express_id])->auto(false)->send();
        if (isset($ret['data']['data'])){
            $ret['data'] = $ret['data']['data'];
        }
        return view('web.common.logistics_info', ['express' => $ret['data']]);
    }

    public function store($order_id)
    {
        $this->validate($this->request, [
            'type' => 'required'
        ]);
        $params = $this->request->all(['type', 'company_code', 'express_company', 'waybill_number']);

        $ret = http_web($this->api_url['store'], [$order_id])->send($params);
        return $ret;
    }
}